<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        class Father {
            constructor(x, y) {
                this.x = x
                this.y = y
                console.log(x, y)
            }
            // 求和
            sum() {
                console.log(this.x + this.y)
            }
        }

        class Son extends Father {
            constructor(x, y) {
                // 1. super必须放在this之前，super表示调用父类的构造函数
                super(x, y)
                // 这里的x,y相当于new的时候，给实例添加属性x, y
                this.x = x

                this.y = y
                this.color = 'orange'
            }
            // 减法
            minus() {
                console.log(this.x - this.y)
            }
        }

        const son = new Son(5, 3)
        console.log(son)
        son.minus()
        son.sum()
    </script>
</body>

</html>